﻿using mvcForum.Core.Abstractions.Interfaces;
using mvcForum.Core.Configuration;
using System;

namespace mvcForum.Core {

	public static class ForumUserExtensions {

		public static String AuthorName(this ForumUser user, IConfiguration config) {
			return user.AuthorName(config.AuthorNameSetting);
		}

		public static String AuthorName(this ForumUser user, AdminAuthorNameSetting setting) {
			switch (setting) {
				case AdminAuthorNameSetting.Username:
					return user.Name;
				case AdminAuthorNameSetting.FullnameOrUsername:
					return String.IsNullOrWhiteSpace(user.FullName) ? user.Name : user.FullName;
				case AdminAuthorNameSetting.EmailAddress:
					return user.EmailAddress;
				case AdminAuthorNameSetting.UserOption:
					return user.UseFullName && !String.IsNullOrWhiteSpace(user.FullName) ? user.FullName : user.Name;
				default:
					throw new ApplicationException("unknown authorname option");
			}
		}
	}
}